package com.megvii.koala.tv.adapter;

import android.content.Context;
import android.widget.TextView;

import com.megvii.corelib.base.MegviiAdapter;
import com.megvii.koala.components.ImageViewEx;
import com.megvii.koala.tv.R;
import com.megvii.koala.tv.data.ThemeBean;

import java.util.List;

import butterknife.Bind;

/**
 * Created by linyue on 16/1/25.
 */
public class ThemeAdapter extends MegviiAdapter<ThemeAdapter.ViewHolder>
{
    private List<ThemeBean> themes;

    public ThemeAdapter(Context context)
    {
        super(context, ViewHolder.class, R.layout.theme_item);
    }

    public void updateDate(List<ThemeBean> themes)
    {
        this.themes = themes;
    }

    @Override
    protected void processViewHolder(ViewHolder viewHolder, int position)
    {
        ThemeBean theme = themes.get(position);
        viewHolder.icon.loadImage(theme.screenshot);
        viewHolder.name.setText(theme.name);
    }

    @Override
    public int getCount()
    {
        return themes != null ? themes.size() : 0;
    }

    @Override
    public Object getItem(int position)
    {
        return themes.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }

    public static class ViewHolder
    {
        @Bind(R.id.theme_icon)
        protected ImageViewEx icon;

        @Bind(R.id.theme_name)
        protected TextView name;
    }
}
